$(function(){
    getUserform()
    var layer = layui.layer
    $('#tc').on('click', function () { 
        layer.confirm('is not?', {icon: 3, title:'你确定要退出'}, function(index){
            localStorage.removeItem('token')
            location.href='./login.html'
        
            layer.close(index);
          })
    })
    

    
})

function getUserform() { 

    $.ajax({

        method: 'get',
        url: '/my/userinfo',
       
        success: function (res) { 
            if (res.status != 0) { 
               
                return
            }
            // 获取头像
            getavver(res.data)

        },
        
    })


}
function getavver(data) { 
    let uname = data.nickname || data.username

    $('#welcome').html(`欢迎 ${uname}`)

    if (data.user_pic) {
        $('.layui-nav-img').attr('src', data.user_pic).show()
        $('.text-avatar').hide()

    } else { 
        let fisrt = uname[0].toUpperCase()
        $('.text-avatar').html(fisrt).show()
        $('.layui-nav-img').hide()
    }



}

